package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportNews;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * created by wangjunfu on 2021-02-24 15:59:45
 */
@Repository
public class TransportNewsDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportNewsDao.class);

    public TransportNews insert(final TransportNews transportNews) {
        insert("TransportNews.insert", transportNews);
        return transportNews;
    }

    public Boolean updateInfoById(final TransportNews transportNews) {
        return update("TransportNews.updateInfoById", transportNews) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportNews.updateInfoByQuery", query) > 0;
    }

    public TransportNews selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("TransportNews.selectById", query);
    }

    public List<TransportNews> selectByQuery(final Query query) {
        return queryForList("TransportNews.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportNews.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        TransportNews transportNews = new TransportNews();
        transportNews.setDeleteFlag(1);
        transportNews.setId(id);
        transportNews.setEntId(entId);

        return update("TransportNews.updateInfoById", transportNews) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportNews.deleteById", query) > 0;
    }

    //以map的形式返回数据
    public List<Map<String, String>> getMapDataByQuery(final Query query, final String element) {
        return queryForList("TransportNews." + element, query);
    }
}